package com.ruoyi.system.amqp;

import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.iot.model.v20180120.*;
import com.aliyuncs.profile.DefaultProfile;
import com.google.gson.Gson;


public class PubDemo {

    public static void main(String[] args) throws Exception {

        DefaultProfile profile = DefaultProfile.getProfile("cn-shanghai", System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"), System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));

        IAcsClient client = new DefaultAcsClient(profile);


        PubRequest request = new PubRequest();
        request.setIotInstanceId("iot-06z00hpv0v1sqpl");
        request.setProductKey("k0yrrTVK6bO");
        request.setTopicFullName("/sys/k0yrrTVK6bO/TxJ5HS6BMdvnMqSGCQFl/thing/service/property/set");
        request.setMessageContent("eyJvcGVyYXRpb24iOiJzZXRNYXhUZW1wZXJhdHVyZSIsImRldmljZUtleSI6InBvaW50XzAwMSIsInJlcXVpcmVQYXJhbXMiOiJ0cnVlIiwicGFyYW1zIjp7ImRhdGEiOiJPSyIsInN0YXR1cyI6MjUwMH0sImRldmljZVNlY3JldCI6IjExMSJ9");

        try {
            PubResponse response = client.getAcsResponse(request);
            System.out.println(new Gson().toJson(response));
        } catch (ServerException e) {
            e.printStackTrace();
        } catch (ClientException e) {
            System.out.println("ErrCode:" + e.getErrCode());
            System.out.println("ErrMsg:" + e.getErrMsg());
            System.out.println("RequestId:" + e.getRequestId());
        }
    }
}